package com.tang.lts.core.nio.handler;

import com.alibaba.fastjson.JSON;
import com.tang.lts.core.nio.channel.NioChannel;
import com.tang.lts.core.nio.idle.IdleState;

import java.util.logging.Level;
import java.util.logging.Logger;

/**
 * @author Tang
 * @classname EventHandler
 * @description [  ]
 * @date 2022/5/12 23:24
 */
public class EventHandler implements NioHandler {

    Logger logger = Logger.getLogger("EventHandler");

    @Override
    public void exceptionCaught(NioChannel channel, Exception cause) {
        logger.log(Level.SEVERE,cause.getMessage());
    }

    @Override
    public void messageReceived(NioChannel channel, Object msg) throws Exception {
        logger.info("messageReceived: " + channel.remoteAddress() + " " + JSON.toJSONString(msg));
    }

    @Override
    public void channelConnected(NioChannel channel) {
        logger.info("channelConnected - " + channel.remoteAddress());
    }

    @Override
    public void channelIdle(NioChannel channel, IdleState state) {

    }
}